<?php 

namespace Admin\Model;
use Think\Model;
class CatModel extends Model{

	public $catall = [];

	public function __construct(){
		parent::__construct();
		$this->catall = $this->select();
	}
	/**
	 * 获取无限级分类
	 * @param $pi 指明父栏目id
	 * @param $fj 指明现在处于第几级 
	 * @return  排好的分类 数组
	 */
	public function getPre($pi = 0,$fj = 0){
		$arr = [];
		foreach ($this->catall as $k => $v) {
			if ($v['parent_id'] == $pi) {
				$v['fj'] = $fj;
				array_push($arr, $v);
				unset($this->catall[$k]);
				$arr = array_merge($arr,$this->getPre($v['cat_id'],$fj+1));
			}	
		}
		return $arr;
	}
}






 ?>